# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=libtermkey
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.22
pkgrel=2
pkgdesc='Library for easy processing of keyboard entry from terminal-based programs (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url='https://www.leonerd.org.uk/code/libtermkey'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-unibilium")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://www.leonerd.org.uk/code/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-make-remove-demos-sources.patch
        0002-libtermkey-make-add-no-undefined.patch)
sha256sums=('6945bd3c4aaa83da83d80a045c5563da4edd7d0374c62c0d35aec09eb3014600'
            '6492da0d94b47628318af8ef863f03d6e36fdb7633e426b80b34668f981c2d21'
            'cb0dbf1fcc481e99a9a720df06662f6d68350e8e1c700fbe111fcbdb25a61a41')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-make-remove-demos-sources.patch"
  patch -p1 -i "${srcdir}/0002-libtermkey-make-add-no-undefined.patch"
}

build() {
  cp -rf "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "build-${MSYSTEM}"

  # for clang undeclared function 'read'
  CFLAGS+=" -Wno-implicit-function-declaration"

  make PREFIX="${MINGW_PREFIX}"
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make PREFIX="${MINGW_PREFIX}" DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
